package com.xb.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xb.entity.DictType;
import com.xb.mapper.DictTypeMapper;
import com.xb.service.IDictTypeService;
import com.xb.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * entityService业务层处理
 */
@Service
public class DictTypeServiceImp implements IDictTypeService {
    @Resource
    private DictTypeMapper dictTypeMapper;

    @Override
    public Result getDictType() {
        Result result = new Result();
        List<DictType> dictType = dictTypeMapper.getDictType();
        result.setData(dictType);
        return result;
    }

    /**
     * 分页查询entity列表
     *
     * @param dictType entity
     * @return entity
     */
    @Override
    public Result selectDictTypeList(DictType dictType, Integer page, Integer limit) {
        Result result = new Result();
        PageHelper.startPage(page, limit);
        List<DictType> list = dictTypeMapper.selectDictTypeList(dictType);
        PageInfo<DictType> dictTypePageInfo = new PageInfo<>(list);
        if (dictTypePageInfo.getList() != null) {
            result.setData(dictTypePageInfo.getList());
            result.setStatus(Result.RESPONSE_SUCCESS);
            result.setTotal(dictTypePageInfo.getTotal());
        }
        return result;
    }

    /**
     * 查询entity列表
     *
     * @param dictType entity
     * @return entity
     */
    @Override
    public List<DictType> selectDictTypeList(DictType dictType) {
        return dictTypeMapper.selectDictTypeList(dictType);
    }

    /**
     * 新增entity
     *
     * @param dictType entity
     * @return 结果
     */
    @Override
    public int insertDictType(DictType dictType) {
        return dictTypeMapper.insertDictType(dictType);
    }

    /**
     * 修改entity
     *
     * @param dictType entity
     * @return 结果
     */
    @Override
    public int updateDictType(DictType dictType) {
        return dictTypeMapper.updateDictType(dictType);
    }

    /**
     * 删除entity信息
     *
     * @param id entityID
     * @return 结果
     */
    @Override
    public int deleteDictTypeById(Integer id) {
        return dictTypeMapper.deleteDictTypeById(id);
    }
}
